package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Life;
import com.noahplat.person.service.LifeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * @ClassName: LifeController
 * @Description: 生活习惯controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/life")
@Validated
public class LifeController {

    @Autowired
    private LifeService lifeService;

    /**
     * 获取生活习惯详情
     * @param pid
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:LifeController:getLife')")
    @GetMapping("/getLife")
    public Result getLife(@NotNull(message = "人员ID不能为空 ") @Min(value = 1, message = "人员ID不合法") Long pid){
        return lifeService.getLife(pid);
    }

    /**
     * 更新生活习惯
     * @param life
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:LifeController:updateLife')")
    @PutMapping("/updateLife")
    public Result updateLife(@RequestBody Life life){
        return lifeService.updateLife(life);
    }

}
